<?php

require_once("conn.php");
$result = true;
$db = new DBC();
if (isset($_GET['ids'])) {
    $ids = $_GET['ids'];
    $ids = trim($ids);
    $array = explode(",", $ids);
    foreach ($array as $productid) {
        if ($productid != '') {
            if (isset($_GET['en']) && $_GET['en'] == '1') {
                $sql = "SELECT * FROM t_product_en WHERE productid = " . $productid;
            } else if (isset($_GET['ios']) && $_GET['ios'] == '1') {
                $sql = "SELECT * FROM t_product_ios WHERE productid = " . $productid;
            } else {
                $sql = "SELECT * FROM t_product WHERE productid = " . $productid;
            }
            $data = $db->fetchData($sql);
            if ($data != null && count($data) > 0) {
                if (file_exists($data[0]['imageURL'])) {
                    unlink($data[0]['imageURL']);
                }
            }
            if (isset($_GET['en']) && $_GET['en'] == '1') {
                $sql = "DELETE FROM t_product_en WHERE productid = " . $productid;
            } else if (isset($_GET['ios']) && $_GET['ios'] == '1') {
                $sql = "DELETE FROM t_product_ios WHERE productid = " . $productid;
            } else {
                $sql = "DELETE FROM t_product WHERE productid = " . $productid;
            }
            if ($db->execute($sql)) {
                //success
                //        echo "<script language='javascript'>alert('\u6210\u529f'); </ script>";
            } else {
                //failue
                $result = false;
            }
        }
    }
}

if (!$result) {
    echo "<script language='javascript'>alert('\u5931\u8d25'); </script>";
}
if (isset($_GET['page'])) {
    $page = $_GET['page'];
} else {
    $page = 0;
}
if (isset($_GET['en']) && $_GET['en'] == '1') {
    echo "<script language='javascript'>location='fileEnList.php?menu=apk&page=" . $page . "';</script>";
} else if (isset($_GET['ios']) && $_GET['ios'] == '1') {
    echo "<script language='javascript'>location='fileIOSList.php?menu=ios&page=" . $page . "';</script>";
} else {
    echo "<script language='javascript'>location='fileList.php?menu=apk&page=" . $page . "';</script>";
}
?>
